package com.ymatou.iapi.selleraccount.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.selleraccount.service.GetSellerSubAccountListCall;
import com.ymatou.iapi.selleraccount.service.QuerySellerRoleListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.YmlCreateRole;
import com.ymttest.database.model.YmtSellerSubAccountRelated;
import com.ymttest.database.sqlwapper.YmlCreateRoleIMapper;
import com.ymttest.database.sqlwapper.YmtSellerSubAccountRelatedIMapper;

public class Tc_GetSellerSubAccountList {
	private static GetSellerSubAccountListCall getSellerSubAccountListCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("业务说明：查询子账号");
	}

	@Before
	public void caseUp() {
		getSellerSubAccountListCall = new GetSellerSubAccountListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getSellerSubAccountListCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerSubAccountList_001(){
		Logger.start(true, "子账号查询");
		try {
			

			JSONObject retBea = new GetSellerSubAccountListCall().callAndGetReturnData();
			JSONObject data = retBea.getJSONObject("Data").getJSONArray("list").getJSONObject(0);
			JSONObject roleDtos = data.getJSONArray("RoleDtos").getJSONObject(0);
			
			int code = retBea.getInt("Code");
			Boolean success = retBea.getBoolean("Success");
			String accountname = data.getString("SellerSubAccountName");
			String email = data.getString("Email");
			int sellerSubAccountUserid = data.getInt("SellerSubAccountID");
			int phonecode = data.getInt("CountryPhoneCode");
			String country = data.getString("Country");
			String phone = data.getString("Phone");
			
			List<YmtSellerSubAccountRelated> account = new YmtSellerSubAccountRelatedIMapper().selectSubAccountRelatedSubsellerUserid(sellerSubAccountUserid);
			YmtSellerSubAccountRelated first =account.get(0);
			String accountnames =first.getSubSellerName();
			String emails = first.getEmail();
			int accountids = first.getSubsellerUserid();
			int phonecodes = first.getSubSellerCountryPhoneCode();
			String countrys = first.getCountry();
			String phones = first.getSubSellerPhone();
			
			Logger.verifyEquals(200, code, "code返回结果");
			Logger.verifyEquals(true, success, "返回结果状态");
			Logger.verifyEquals(accountname, accountnames, "子账号名称");
			Logger.verifyEquals(email, emails, "子账号注册邮箱");
			Logger.verifyEquals(sellerSubAccountUserid, accountids, "子账号ID");
			Logger.verifyEquals(phonecode, phonecodes, "子账号注册国ID");
			Logger.verifyEquals(country, countrys, "子账号注册国名称");
			Logger.verifyEquals(phone, phones, "子账号注册手机号");
			Logger.verifyNotNull(roleDtos, "子账号角色非空");
			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerSubAccountList_002 (){
		Logger.start(true, "子账号角色查询--主账号不存在");
		try{
			
			int sellerid = 338999;
			
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("SellerId",sellerid);
			
			JSONObject retBea = new GetSellerSubAccountListCall().callAndGetReturnData(map1);
			JSONObject data = retBea.getJSONObject("Data");
			String roledtos = data.getString("list");
			
			int code = retBea.getInt("Code");
			Boolean success = retBea.getBoolean("Success");
			
			
			
			Logger.verifyEquals(200, code, "code返回结果");
			Logger.verifyEquals(true, success, "返回结果状态");
			Logger.verifyEquals("[]", roledtos, "返回结果为空");

			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerSubAccountList_003 (){
		Logger.start(true, "子账号角色查询--分页错误");
		try{
			
			int size = 0;
			int index = 0;
			
			Map<String,Object> map1 = new HashMap<String,Object>();
			map1.put("PageSize",size);
			map1.put("PageIndex",index);
			
			JSONObject retBea = new GetSellerSubAccountListCall().callAndGetReturnData(map1);
			JSONObject data = retBea.getJSONObject("Data");
			String roledtos = data.getString("list");
			
			int code = retBea.getInt("Code");
			Boolean success = retBea.getBoolean("Success");
			
			
			
			Logger.verifyEquals(200, code, "code返回结果");
			Logger.verifyEquals(true, success, "返回结果状态");
			Logger.verifyEquals("[]", roledtos, "返回结果为空");

			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}

}
